<?php
	require_once $ubi['SERVER']['SERVER_ROOT'] . '/dao/daoAddress.php';
	
	class AddressBus {
		private $_addressDao;	
	
		public function __construct() {
			$this->_addressDao = new AddressDao();		
		}
		
		public function addAddress($address) {
			$address->setCity(GeneralFunctions::stripString($address->getCity()));
			$address->setDistrict(GeneralFunctions::stripString($address->getDistrict()));
			$address->setNumber(GeneralFunctions::stripString($address->getNumber()));
			$address->setStreet(GeneralFunctions::stripString($address->getStreet()));
			$address->setWard(GeneralFunctions::stripString($address->getWard()));
			
			return $this->_addressDao->addAddress($address);
		}		
		
		public function deleteAddress($addressId) {
			$this->_addressDao->deleteAddress($addressId);
		}
		
		public function getAddress($addressID) {
			return $this->_addressDao->getAddress($addressID);
		}
		
		public function getAddressString($addressID) {
			$add = $this->_addressDao->getAddress($addressID);
			if ($add != null) {
				$str = $add->getNumber() . ', ' . $add->getStreet() . ', ' . $add->getWard() . ', ' . $add->getDistrict() . ', ' . $add->getCity();
				return $str;
			}
		}
		
		public function updateAddress($address) {
			$address->setCity(GeneralFunctions::stripString($address->getCity()));
			$address->setDistrict(GeneralFunctions::stripString($address->getDistrict()));
			$address->setNumber(GeneralFunctions::stripString($address->getNumber()));
			$address->setStreet(GeneralFunctions::stripString($address->getStreet()));
			$address->setWard(GeneralFunctions::stripString($address->getWard()));
			
			return $this->_addressDao->updateAddress($address);
		}
	} 
?>